alpha <- c(2, 4)
sigmasq.n <- c(.8, 1)
seq(11:20)
c(11:20)
c(.8,1)
c(11:20)
ls()
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files")
require("readstata13")
data <- readstata13("harris_s901209_sas.dta")
data <- read.dta13("harris_s901209_sas.dta")
head(data)
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1990 Business Week National Issues Survey, study no. 901209")
require("data.table")
data <- read.table("harris_s901209_spss.tab")
head(data)
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1969 American Foreign Policy Survey, study no. 1970")
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1966 National Election Survey, study no. 1623")
survey_1623 <- readRDS("survey_1623.RDS")
colnames(survey_1623) == c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")
survey.check <- readRDS("survey_1623.RDS")
survey.check$pid == c(1:nrow(survey.check))
sum(survey.check$pid != c(1:nrow(survey.check)))
survey.check$study == 1623
sum(survey.check$study != 1623)
sum(survey.check$year != 1966)
levels(survey.check$urban)
class(survey.check$urban)
survey.check$urban
sum(!is.na(survey.check$urban))
class(survey.check$region)
levels(survey.check$region)
class(survey.check$hh)
levels(survey.check$hh) ## should be Yes, No, Not sure,
class(survey.check$hh) ## should be logical or factor
sum(!is.na(survey.check$hh)) ## if all NAs
levels(survey.check$region) ## should be West, East, Midwest, South
levels(survey.check$hh) ## should be Yes, No, Not sure,
sum(!is.na(survey.check$hh)) ## if all NAs
class(survey.check$inequality)
levels(survey.check$inequality)
summary(survey.check$inequality.variable)
class(survey.check$union.other)
class(survey.check$union.other)
class(survey.check$union.self)
levels(survey.check$union.other) # Yes, No, Not Sure
sum(!is.na(survey.check$union.other))
sum(!is.na(survey.check$union.self)) # if all NAs - should be zero
class(survey.check$employed)
class(survey.check$occupation)
class(survey.check$occupation) # factor unordered or logical
class(survey.check$hhsize)
sum(!is.na(survey.check$employed))
class(survey.check$educ)
levels(survey.check$educ)
levels(survey.check$educ) == c("Less than high school","High school graduate",
"Some college", "College graduate", "Post graduate")
sum(!is.na(survey.check$educ)) # if all NAs - should be zero
class(survey.check$income)
sum(!is.na(survey.check$income)) # if all NAs - should be zero
class(survey.check$age)
levels(survey.check$age)
sum(!is.na(survey.check$age)) # if all NAs - should be zero
class(survey.check$race)
sum(!is.na(survey.check$race)) # if all NAs - should be zero
class(survey.check$party)
sum(!is.na(survey.check$party)) # if all NAs - should be zero
levels(survey.check$employed)
levels(survey.check$occupation)
class(survey.check$hhsize) # factor unordered or logical
levels(suvey.check$hhsize)
levels(survey.check$hhsize)
levels(survey.check$income)
levels(survey.check$age)
levels(survey.check$race)
levels(survey.check$party)
class(survey.check$ideology)
sum(!is.na(survey.check$ideology))
levels(survey.check$ideology)
class(survey.check$gender)
sum(!is.na(survey.check$gender))
levels(survey.check$gender)
class(survey.check$religion)
sum(!is.na(survey.check$religion))
levels(survey.check$religion)
as.character(1623)
setwd("~/Dropbox/Perception_Inequality_wHannah/Survey Files/Harris 1966 National Election Survey, study no. 1623")
library(dplyr)
library(tidyr)
library(readstata13)
survey <- read.dta13("harris_s1623_spss.dta")
# pid
survey$pid <- c(1:nrow(survey))
# study number (study)
survey$study <- as.character(1623)
# study year (year)
survey$year <- 1966
# geographic data (urban)
survey$urban <- NA
# geographic region (region)
summary(survey$region)
survey$region <- ifelse(survey$region == "East_(1)", "East",
ifelse(survey$region == "East_(2)", "East",
ifelse(survey$region == "South_(3)", "South",
ifelse(survey$region == "South_(4)", "South",
ifelse(survey$region == "Midwest_(5)", "Midwest",
ifelse(survey$region == "Midwest_(6)", "Midwest",
ifelse(survey$region == "West_(7)", "West", "West")))))))
survey$region <- as.factor(survey$region)
summary(survey$region)
# head of household (hh)
survey$hh <- NA
# inequality increasing (inequality)
summary(survey$P19A_1) # already harmonised
survey$inequality <- survey$P19A_1
survey$inequality <- recode(survey$inequality, `Don t feel` = "Don't Feel",
`Not sure` = "Not Sure")
summary(survey$inequality)
class(survey$inequality)
# inequality variable
survey$inequality.variable <- 1
# union (union.self)
summary(survey$F4_1) # already harmonized
survey$union.self <- survey$F4_1
summary(survey$F4_2) # already harmonized
survey$union.other <- survey$F4_2
# employed and type (employed)
survey$employed <- survey$F2
summary(survey$employed)
class(survey$employed)
# employment 2 (occupation)
survey$occupation <- survey$F3
# household size (hhsize)
survey$hhsize <- survey$F7
# education (educ)
summary(survey$F11)
levels(survey$F11)
survey$educ <- ifelse(survey$F11 == "8th grade or less", "Less than high school",
ifelse(survey$F11 == "Some high school", "Less than high school",
ifelse(survey$F11 == "High school graduate", "High school graduate",
ifelse(survey$F11 == "Some college", "Some college",
ifelse(survey$F11 == "College graduate", "College graduate",
ifelse(survey$F11 == "Post graduate", "Post graduate",
NA))))))
survey$educ <- as.factor(survey$educ)
summary(survey$educ)
class(survey$educ)
levels(survey$educ)
survey$educ <- factor(survey$educ, levels = c("Less than high school", "High school graduate",
"Some college", "College graduate", "Post graduate"),
labels = c("Less than high school", "High school graduate",
"Some college", "College graduate", "Post graduate"),
ordered = TRUE)
class(survey$educ)
summary(survey$F11)
# household income (income)
survey$income <- survey$F14
# age (age)
survey[!is.na(survey$F13_1) & !is.na(survey$F13_2), c("F13_1", "F13_2")]
survey$age <- ifelse(is.na(survey$F13_1), as.character(survey$F13_2),
as.character(survey$F13_1))
summary(survey$age)
survey$age <- factor(survey$age)
# race
survey$race <- survey$F15
# political orientation (party)
survey$party <- survey$Q2A
# ideology
survey$ideology <- NA
# gender
survey$gender <- ifelse(is.na(survey$F13_1) & !is.na(survey$F13_2), "Female",
ifelse(is.na(survey$F13_2) & !is.na(survey$F13_1), "Male", NA))
survey$gender <- as.factor(survey$gender)
summary(survey$gender)
# religion
survey$religion <- survey$F12
# subset
survey_1623 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
"inequality", "inequality.variable", "union.self", "union.other",
"employed", "occupation", "hhsize", "educ", "income",
"age", "race", "party", "ideology", "gender", "religion")]
summary(survey_1623)
# save file
saveRDS(survey_1623, file = "survey_1623.rds")
